Skip to content

Picker: support custom default date via setDefaultDate (#4973)#4974

Merged
shai-almog merged 3 commits into
masterfrom
picker-default-date
May 18, 2026
Merged

Picker: support custom default date via setDefaultDate (#4973)#4974
shai-almog merged 3 commits into
masterfrom
picker-default-date

Conversation

@shai-almog
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Picker.DateGetter plus setDefaultDate(DateGetter) / setDefaultDate(Date) so date-type pickers (PICKER_TYPE_DATE, PICKER_TYPE_DATE_AND_TIME, PICKER_TYPE_CALENDAR) can show a caller-supplied initial value instead of always defaulting to new Date().
  • The getter is evaluated lazily each time the picker opens (or getDate() is called against an unset picker), so dependent defaults like "reminder = due date - 1 hour" stay in sync with the value they depend on.
  • After a successful selection the chosen value pins the picker and the getter stops being consulted; setDate(null) (or switching off a date type) re-enables it. Cancel paths — including a Cancel after a custom lightweight-popup button that internally called setDate(...) — roll back to the pre-edit explicit-flag, so the default getter keeps working on the next open.

Implements #4973.

Test plan

  • mvn -pl core -am compile succeeds (verified locally).
  • Sample app with Picker.setType(PICKER_TYPE_DATE) + setDefaultDate(() -> dueDate.minusHours(1)) shows the resolved default when opened without a prior setDate.
  • After accepting a date in the picker, subsequent opens show the accepted value (not the dynamic default).
  • setDate(null) re-enables the dynamic default on the next open.
  • Lightweight popup: a custom "+7 days" button followed by Cancel rolls back to the pre-edit default behavior (not the staged date).
  • Pickers with no setDefaultDate call behave exactly as before.

🤖 Generated with Claude Code

Adds Picker.DateGetter plus setDefaultDate(DateGetter)/setDefaultDate(Date)
so PICKER_TYPE_DATE, PICKER_TYPE_DATE_AND_TIME, and PICKER_TYPE_CALENDAR
pickers can show a caller-supplied initial value (resolved lazily on each
open) instead of always defaulting to `new Date()`. After a successful
selection the picked value pins the picker and the getter is no longer
consulted; clearing with setDate(null) (or switching off a date type)
re-enables it. Custom lightweight popup buttons that call setDate during
edit are snapshotted/rolled back on Cancel so default-getter behavior
survives a cancelled action. getDate() returns the resolved default when
no explicit value has been set so the UI and programmatic read agree.
Behavior with no setDefaultDate call is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 18, 2026

Compared 107 screenshots: 107 matched.

Native Android coverage

  • 📊 Line coverage: 11.51% (6375/55367 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 9.18% (31673/344940), branch 3.95% (1294/32776), complexity 5.06% (1591/31431), method 8.85% (1302/14708), class 14.90% (297/1993)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 11.51% (6375/55367 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 9.18% (31673/344940), branch 3.95% (1294/32776), complexity 5.06% (1591/31431), method 8.85% (1302/14708), class 14.90% (297/1993)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 737.000 ms
Base64 CN1 encode 116.000 ms
Base64 encode ratio (CN1/native) 0.157x (84.3% faster)
Base64 native decode 882.000 ms
Base64 CN1 decode 232.000 ms
Base64 decode ratio (CN1/native) 0.263x (73.7% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 18, 2026

Compared 107 screenshots: 107 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 339 seconds

Build and Run Timing

Metric Duration
Simulator Boot 90000 ms
Simulator Boot (Run) 1000 ms
App Install 18000 ms
App Launch 6000 ms
Test Execution 281000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 1621.000 ms
Base64 CN1 encode 2182.000 ms
Base64 encode ratio (CN1/native) 1.346x (34.6% slower)
Base64 native decode 990.000 ms
Base64 CN1 decode 1418.000 ms
Base64 decode ratio (CN1/native) 1.432x (43.2% slower)
Base64 SIMD encode 518.000 ms
Base64 encode ratio (SIMD/native) 0.320x (68.0% faster)
Base64 encode ratio (SIMD/CN1) 0.237x (76.3% faster)
Base64 SIMD decode 711.000 ms
Base64 decode ratio (SIMD/native) 0.718x (28.2% faster)
Base64 decode ratio (SIMD/CN1) 0.501x (49.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 128.000 ms
Image createMask (SIMD on) 32.000 ms
Image createMask ratio (SIMD on/off) 0.250x (75.0% faster)
Image applyMask (SIMD off) 221.000 ms
Image applyMask (SIMD on) 61.000 ms
Image applyMask ratio (SIMD on/off) 0.276x (72.4% faster)
Image modifyAlpha (SIMD off) 247.000 ms
Image modifyAlpha (SIMD on) 55.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.223x (77.7% faster)
Image modifyAlpha removeColor (SIMD off) 214.000 ms
Image modifyAlpha removeColor (SIMD on) 70.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.327x (67.3% faster)
Image PNG encode (SIMD off) 1326.000 ms
Image PNG encode (SIMD on) 1059.000 ms
Image PNG encode ratio (SIMD on/off) 0.799x (20.1% faster)
Image JPEG encode 908.000 ms

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 18, 2026

Compared 107 screenshots: 107 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 296 seconds

Build and Run Timing

Metric Duration
Simulator Boot 97000 ms
Simulator Boot (Run) 1000 ms
App Install 14000 ms
App Launch 8000 ms
Test Execution 325000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 5151.000 ms
Base64 CN1 encode 2604.000 ms
Base64 encode ratio (CN1/native) 0.506x (49.4% faster)
Base64 native decode 1236.000 ms
Base64 CN1 decode 1839.000 ms
Base64 decode ratio (CN1/native) 1.488x (48.8% slower)
Base64 SIMD encode 691.000 ms
Base64 encode ratio (SIMD/native) 0.134x (86.6% faster)
Base64 encode ratio (SIMD/CN1) 0.265x (73.5% faster)
Base64 SIMD decode 529.000 ms
Base64 decode ratio (SIMD/native) 0.428x (57.2% faster)
Base64 decode ratio (SIMD/CN1) 0.288x (71.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 92.000 ms
Image createMask (SIMD on) 10.000 ms
Image createMask ratio (SIMD on/off) 0.109x (89.1% faster)
Image applyMask (SIMD off) 273.000 ms
Image applyMask (SIMD on) 88.000 ms
Image applyMask ratio (SIMD on/off) 0.322x (67.8% faster)
Image modifyAlpha (SIMD off) 169.000 ms
Image modifyAlpha (SIMD on) 130.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.769x (23.1% faster)
Image modifyAlpha removeColor (SIMD off) 188.000 ms
Image modifyAlpha removeColor (SIMD on) 132.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.702x (29.8% faster)
Image PNG encode (SIMD off) 1433.000 ms
Image PNG encode (SIMD on) 1187.000 ms
Image PNG encode ratio (SIMD on/off) 0.828x (17.2% faster)
Image JPEG encode 740.000 ms

SpotBugs (SIC_INNER_SHOULD_BE_STATIC_ANON) flagged the anonymous
DateGetter created by setDefaultDate(Date) - it captures no Picker
state, so promoting it to a named static inner class avoids the
hidden enclosing-Picker reference and clears the CI gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

Covers: fixed default, dynamic getter re-evaluation, explicit setDate
override, setDate(null) re-enables default, clearing the getter,
getDefaultDate accessor, setType-off-and-back reset, DATE_AND_TIME
support, null-returning getter falls back to new Date(), and the
custom-popup-button cancel rollback path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shai-almog shai-almog merged commit 9a240c0 into master May 18, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFE: Add support to set your own default Picker values in addition to the current 'now'

1 participant